# pytorch基本算法操作
import torch
'''
注意：
任何使张量会发生变化的操作都有一个前缀 ‘_’。例如：x.copy_(y), x.t_(), 将会改变 x.
'''

x1=torch.rand(5,3)
y1=torch.rand(5,3)
z1=x1+y1    # python本来的加减
#print('z1',z1)
'''
结果展示：
z1 tensor([[0.7648, 0.7006, 0.6031],
        [1.0173, 1.9059, 0.6729],
        [0.6648, 1.3639, 0.2374],
        [0.5715, 0.6160, 0.4857],
        [0.4412, 0.1789, 1.5316]])
'''

z1_2=torch.add(x1,y1)    # pytorch的加法
#print('z1_2',z1_2)
'''
结果展示：
z1_2 tensor([[0.5851, 1.2860, 1.3611],
        [0.5233, 1.4249, 0.8745],
        [0.7863, 1.1087, 1.3915],
        [1.1041, 1.0204, 1.2896],
        [0.9860, 1.5950, 1.5396]])
'''

result=torch.empty(5,3)
torch.add(x1,y1,out=result)   # 输出到指定张量
#print('result',result)
'''
结果展示：
result tensor([[0.8393, 0.8951, 0.9389],
        [1.4092, 1.0693, 1.1186],
        [1.0180, 1.0359, 0.8506],
        [0.8217, 0.8142, 0.8199],
        [0.7861, 0.9637, 0.9161]])
'''

y1.add_(x1)    # 把x1加到y1上
print('y1',y1)
'''
结果展示：
y1 tensor([[1.2006, 0.7541, 1.3323],
        [1.0900, 0.9068, 0.7736],
        [1.7936, 1.6133, 1.8794],
        [0.6150, 0.6323, 0.8207],
        [1.2613, 1.2443, 0.9985]])
'''


